var a = getApp();

Component({
    properties: {
        show: {
            type: Boolean,
            value: !1
        }
    },
    pageLifetimes: {
        show: function() {
            this._initAddressInfo();
        }
    },
    observers: {
        show: function(a) {
            console.log(a), a && this.setData({
                showArea: a
            });
        }
    },
    data: {
        showArea: !1,
        pickerValue: [ 0, 0, 0 ],
        provinceData: [],
        cityData: [],
        districtData: []
    },
    methods: {
        _initAddressInfo: function() {
            var t = this;
            wx.getStorage({
                key: "provinceData",
                success: function(a) {
                    console.log("地址信息准备就绪"), t._getProvinceData();
                },
                fail: function(e) {
                    console.log("省fail"), a._getNetWork({
                        url: a.getNetAddresss("member.member-address.address"),
                        success: function(a) {
                            var e = a.data, s = e.data.province, i = e.data.city, d = e.data.district;
                            wx.setStorage({
                                key: "provinceData",
                                data: s
                            }), wx.setStorage({
                                key: "cityData",
                                data: i
                            }), wx.setStorage({
                                key: "districtData",
                                data: d
                            }), t._initAddressInfo();
                        },
                        fail: function(a) {},
                        state: !0
                    });
                }
            });
        },
        _getProvinceData: function() {
            var a = this;
            wx.getStorage({
                key: "provinceData",
                success: function(t) {
                    a.setData({
                        provinceData: t.data
                    }), a.setData({
                        "selectAddressData[0].name": t.data[a.data.pickerValue[0]].areaname,
                        "selectAddressData[0].id": t.data[a.data.pickerValue[0]].id,
                        "selectAddressData[0].index": a.data.pickerValue[0]
                    }), a._getCityData();
                }
            });
        },
        _getCityData: function() {
            var a = this.data.selectAddressData[0], t = this;
            wx.getStorage({
                key: "cityData",
                success: function(e) {
                    for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == a.id && s.push(e.data[i]);
                    t.setData({
                        cityData: s
                    }), t.setData({
                        "selectAddressData[1].name": s[t.data.pickerValue[1]].areaname,
                        "selectAddressData[1].id": s[t.data.pickerValue[1]].id,
                        "selectAddressData[1].index": t.data.pickerValue[1]
                    }), t._getDistrictData();
                }
            });
        },
        _getDistrictData: function() {
            var a = this.data.selectAddressData[1], t = this;
            wx.getStorage({
                key: "districtData",
                success: function(e) {
                    for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == a.id && s.push(e.data[i]);
                    t.setData({
                        districtData: s
                    }), t.setData({
                        "selectAddressData[2].name": s[t.data.pickerValue[2]].areaname,
                        "selectAddressData[2].id": s[t.data.pickerValue[2]].id,
                        "selectAddressData[2].index": t.data.pickerValue[2]
                    }), console.log("over", t.data.selectAddressData);
                }
            });
        },
        bindChange: function(a) {
            var t = a.detail.value;
            this.data.pickerValue[0] != t[0] && (t[1] = 0, t[2] = 0), this.data.pickerValue[1] != t[1] && (t[2] = 0), 
            this.setData({
                "pickerValue[0]": t[0],
                "pickerValue[1]": t[1],
                "pickerValue[2]": t[2]
            }), this._initAddressInfo();
        },
        onClickLeft: function() {
            this.setData({
                showArea: !1
            });
        },
        onClickRight: function() {
            var a = this.data.selectAddressData;
            this.onClickLeft(), console.log("确定选择收货地址", a), this.triggerEvent("confirm", a);
        }
    }
});